package com.sumainfor.pc.epc.service.impl;


import com.sumainfor.common.Constants;
import com.sumainfor.common.util.CustomMap;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.*;
import com.sumainfor.pc.epc.dao.TcepcArticleMapper;
import com.sumainfor.pc.epc.dao.UtilsMapper;
import com.sumainfor.pc.epc.feign.GmioFeign;
import com.sumainfor.pc.epc.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.epc.feign.Zfeign.ZzuulFeign;
import com.sumainfor.pc.epc.service.TcepcArticleService;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>
 * 查询报修物品相关清单
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-04-16 15:15
 **/
@Service
public class TcepcArticleServiceImpl implements TcepcArticleService {
    private ReentrantLock lock = new ReentrantLock(false);
    Logger log = LoggerFactory.getLogger(TcepcArticleServiceImpl.class);

    @Autowired
    TcepcArticleMapper tcepcArticleMapper;

    @Autowired
    ZpcMktFeign zpcMktFeign;

    @Autowired
    ZzuulFeign zzuulFeign;

    @Autowired
    GmioFeign gmioFeign;

    @Autowired
    UtilsMapper utilsMapper;


    /**
     * <p>
     * 查询受理中的维修工单
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult toAccept(Map<String, Object> params) {
        JsonResult resultone = new JsonResult();
        List<Map<String, Object>> para = tcepcArticleMapper.toAccept(params);
        System.out.println("查询的参数" + para);
        if (para.size() > 0) {
            //保存房源配置主表编号
            List<String> HouConList = new ArrayList<>();
            for (Map<String, Object> par : para) {
                if (par.get("HouCon") != null) {
                    HouConList.add(MapUtils.getString(par, "HouCon"));
                }
            }
            if (HouConList.size() > 0) {//根据房源配置主表编号去市场部查询房源信息
                params.put("idList", HouConList);
                JsonResult result = zpcMktFeign.getCommunityListss(params);
                List<Map<String, Object>> mktList = (List<Map<String, Object>>) result.get("result");
                System.out.println("mktList" + mktList);
                if (result.get("errorCode").equals("0")) {
                    for (Map<String, Object> map : para) {
                        for (Map<String, Object> map2 : mktList) {
                            if (MapUtils.getString(map, "HouCon") != null && MapUtils.getString(map2, "HouCon") != null && MapUtils.getString(map, "HouCon").equals(MapUtils.getString(map2, "HouCon"))) {
                                map.putAll(map2);
                                System.out.println("map" + map);
                            }
                        }
                    }
                }

            }
            return resultone.put(para);
        }
        return resultone.put(new ArrayList<Map<String, Object>>());

    }

    /**
     * <p>
     * 查询待上门
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult forTheDoor(Map<String, Object> params) {
        JsonResult resultone = new JsonResult();
        List<Map<String, Object>> para = tcepcArticleMapper.forTheDoor(params);
        System.out.println("para" + para);
        if (para.size() > 0) {
            //保存房源配置主表编号
            List<String> HouConList = new ArrayList<>();
            //保存维修师傅的编号
            List<String> SysUserIdList = new ArrayList<>();
            for (Map<String, Object> par : para) {
                if (par.get("HouCon") != null) {
                    HouConList.add(MapUtils.getString(par, "HouCon"));
                }
                if (par.get("SysUserId") != null) {
                    SysUserIdList.add(MapUtils.getString(par, "SysUserId"));
                }
            }
            if (HouConList.size() > 0) {//根据房源配置主表编号去市场部查询房源信息
                params.put("idList", HouConList);
                JsonResult result = zpcMktFeign.getCommunityListss(params);
                List<Map<String, Object>> mktList = (List<Map<String, Object>>) result.get("result");
                ;
                System.out.println("mktList" + mktList);
                if (result.get("errorCode").equals("0")) {
                    for (Map<String, Object> map : para) {
                        for (Map<String, Object> map2 : mktList) {
                            if (MapUtils.getString(map, "HouCon") != null && MapUtils.getString(map2, "HouCon") != null && MapUtils.getString(map, "HouCon").equals(MapUtils.getString(map2, "HouCon"))) {
                                map.putAll(map2);
                                System.out.println("map" + map);
                            }
                        }
                    }
                }
            }
            if (SysUserIdList.size() > 0) {//根据维修师傅编号去权限表查询维修师傅的名字
                params.put("SysUserId", SysUserIdList);
                JsonResult SysResult = zzuulFeign.getLoginName(params);//查询维修师傅的姓名
                List<Map<String, Object>> SysList = (List<Map<String, Object>>) SysResult.get("result");
                System.out.println("找到维修师傅名字的SysList" + SysList);
                if (SysResult.get("errorCode").equals("0")) {
                    for (Map<String, Object> map1 : para) {
                        for (Map<String, Object> map2 : SysList) {
                            if (MapUtils.getString(map1, "SysUserId") != null && MapUtils.getString(map2, "user_id") != null && MapUtils.getString(map1, "SysUserId").equals(MapUtils.getString(map2, "user_id"))) {
                                map1.putAll(map2);
                                System.out.println("map1" + map1);
                            }
                        }
                    }
                }
            }
            return resultone.put(para);
        }
        return resultone.put(new ArrayList<Map<String, Object>>());

    }





    /**
     * <p>
     * 查询待支付(维修工单需要收费，维修已经完成，但是没有支付)
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult toBePaid(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        System.out.println("待评价接受的参数" + params);
        List<Map<String, Object>> evaluateList = tcepcArticleMapper.toEvaluate(params);
        System.out.println("查询维修完成(不管是否收费)" + evaluateList);
        //保存房源配置主表编号(收费)
        List<String> HouConYesList = new ArrayList<>();
        //保存维修师傅的编号（收费）
        List<String> SysUserIdYesList = new ArrayList<>();
        //保存维修账单的编号（收费）
        List<String> OrdBiIdYesList = new ArrayList<>();
        //保存维修完成，收费 和待付款和未评价的集合
        List<Map<String, Object>> IfCostYesList = new ArrayList<>();
        if (evaluateList.size() > 0) {
            for (Map<String, Object> evaluateMap : evaluateList) {
                if (evaluateMap.get("IfCost") != null && MapUtils.getInteger(evaluateMap, "IfCost") == 1) {//检查收费
                    if (evaluateMap.get("RepId") != null && tcepcArticleMapper.toEvaluateBeenCompleted(evaluateMap) == 0) {//检查未评价
                        HouConYesList.add(MapUtils.getString(evaluateMap, "HouCon"));
                        SysUserIdYesList.add(MapUtils.getString(evaluateMap, "SysUserId"));
                        OrdBiIdYesList.add(MapUtils.getString(evaluateMap, "OrdBiId"));
                        IfCostYesList.add(evaluateMap);
                    }
                }
            }
            if (IfCostYesList.size() > 0) {
                System.out.println("已支付的房源" + HouConYesList);
                if (HouConYesList.size() > 0) {//根据房源配置主表编号去市场部查询房源信息
                    params.put("idList", HouConYesList);
                    JsonResult zpcResult = zpcMktFeign.getCommunityListss(params);
                    List<Map<String, Object>> zpcList = (List<Map<String, Object>>) zpcResult.get("result");
                    System.out.println("zpcList" + zpcList);
                    if (zpcResult.get("errorCode").equals("0")) {
                        for (Map<String, Object> map : IfCostYesList) {
                            for (Map<String, Object> map2 : zpcList) {
                                if (MapUtils.getString(map, "HouCon") != null && MapUtils.getString(map2, "HouCon") != null && MapUtils.getString(map, "HouCon").equals(MapUtils.getString(map2, "HouCon"))) {
                                    map.putAll(map2);
                                    System.out.println("map" + map);
                                }
                            }
                        }
                    }
                }
                System.out.println("未支付的维修师傅" + SysUserIdYesList);
                if (SysUserIdYesList.size() > 0) {//根据维修师傅编号去权限表查询维修师傅的名字
                    params.put("SysUserId", SysUserIdYesList);
                    JsonResult SysResult = zzuulFeign.getLoginName(params);//查询维修师傅的姓名
                    List<Map<String, Object>> SysList = (List<Map<String, Object>>) SysResult.get("result");
                    System.out.println("找到维修师傅名字的SysList" + SysList);
                    if (SysResult.get("errorCode").equals("0")) {
                        for (Map<String, Object> map1 : IfCostYesList) {
                            for (Map<String, Object> map2 : SysList) {
                                if (MapUtils.getString(map1, "SysUserId") != null && MapUtils.getString(map2, "user_id") != null && MapUtils.getString(map1, "SysUserId").equals(MapUtils.getString(map2, "user_id"))) {
                                    map1.putAll(map2);
                                    System.out.println("map1" + map1);
                                }
                            }
                        }
                    }
                }

                //修改之后
                System.out.println("未支付的账单" + OrdBiIdYesList);


                if (OrdBiIdYesList.size() > 0) {//根据账单编号查询是否支付
                    params.put("OrdBiIdList", OrdBiIdYesList);
                    JsonResult OrdResult = gmioFeign.getTcmgioBillOne(params);
                    List<Map<String, Object>> OrdList = (List<Map<String, Object>>) OrdResult.get("result");
                    System.out.println("支付过的维修工单" + OrdList);
                    if (OrdList!=null&&OrdList.size()>0) {
                        if (OrdResult.get("errorCode").equals("0")) {
                            for (Map<String, Object> map1 : IfCostYesList) {
                                for (Map<String, Object> map2 : OrdList) {
                                    if (MapUtils.getString(map1, "OrdBiId") != null && MapUtils.getString(map2, "Source") != null && MapUtils.getString(map1, "OrdBiId").equals(MapUtils.getString(map2, "Source"))) {
                                        map1.putAll(map2);
                                        System.out.println("map1" + map1);
                                    }
                                }
                            }
                        }

                        for (int i=0;i<IfCostYesList.size();i++){
                            if (MapUtils.getInteger(IfCostYesList.get(i),"Status")!=1||null==MapUtils.getInteger(IfCostYesList.get(i),"Status")){
                                IfCostYesList.remove(i);
                            }
                        }


                    }else{
                        return result.put(new ArrayList<Map<String, Object>>());
                    }


                }



            } else {
                return result.put(new ArrayList<Map<String, Object>>());
            }
            List<Map<String, Object>> resultList = new ArrayList<>();
            resultList.addAll(IfCostYesList);
            return result.put(resultList);
        } else {
            return result.put(new ArrayList<Map<String, Object>>());
        }
    }














    /**
     * <p>
     * 查询待评价
     * <p>
     * 查询待评价的维修工单（收费和未收费）
     * 1，不收费并且维修完成，没有评价 2，收费并且维修完成，没有评价
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult toEvaluate(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        System.out.println("待评价接受的参数" + params);
        List<Map<String, Object>> evaluateList = tcepcArticleMapper.toEvaluate(params);
        System.out.println("查询维修完成(不管是否收费)" + evaluateList);
        Map<String, Object> paramsYes = new HashMap<>();
        //保存房源配置主表编号(未收费)
        List<String> HouConNoList = new ArrayList<>();
        //保存维修师傅的编号（未收费）
        List<String> SysUserIdNoList = new ArrayList<>();
        //保存房源配置主表编号(收费)
        List<String> HouConYesList = new ArrayList<>();
        //保存维修师傅的编号（收费）
        List<String> SysUserIdYesList = new ArrayList<>();
        //保存维修账单的编号（收费）
        List<String> OrdBiIdYesList = new ArrayList<>();
        //保存维修完成未收费和未评价的集合
        List<Map<String, Object>> IfCostNoList = new ArrayList<>();
        //保存维修完成，收费 和付款成功和未评价的集合
        List<Map<String, Object>> IfCostYesList = new ArrayList<>();
        if (evaluateList.size() > 0) {
            for (Map<String, Object> evaluateMap : evaluateList) {
                if (evaluateMap.get("IfCost") != null && MapUtils.getInteger(evaluateMap, "IfCost") == 0) {//检查不收费
                    if (evaluateMap.get("RepId") != null && tcepcArticleMapper.toEvaluateBeenCompleted(evaluateMap) == 0) {//检查未评价
                        HouConNoList.add(MapUtils.getString(evaluateMap, "HouCon"));//不收费的房源
                        SysUserIdNoList.add(MapUtils.getString(evaluateMap, "SysUserId"));//不收费的师傅
                        IfCostNoList.add(evaluateMap);
                    }
                }


                if (evaluateMap.get("IfCost") != null && MapUtils.getInteger(evaluateMap, "IfCost") == 1) {//检查收费
                    if (evaluateMap.get("RepId") != null && tcepcArticleMapper.toEvaluateBeenCompleted(evaluateMap) == 0) {//检查未评价
                        HouConYesList.add(MapUtils.getString(evaluateMap, "HouCon"));//收费房源
                        SysUserIdYesList.add(MapUtils.getString(evaluateMap, "SysUserId"));//收费师傅
                        OrdBiIdYesList.add(MapUtils.getString(evaluateMap, "OrdBiId"));//收费账单编号
                        IfCostYesList.add(evaluateMap);
                    }
                }


            }
            System.out.println("不收费的房源" + HouConNoList);
            if (HouConNoList.size() > 0) {//根据房源配置主表编号去市场部查询房源信息
                params.put("idList", HouConNoList);
                JsonResult zpcResult = zpcMktFeign.getCommunityListss(params);
                List<Map<String, Object>> zpcList = (List<Map<String, Object>>) zpcResult.get("result");
                System.out.println("zpcList" + zpcList);
                if (zpcResult.get("errorCode").equals("0")) {
                    for (Map<String, Object> map : IfCostNoList) {
                        for (Map<String, Object> map2 : zpcList) {
                            if (MapUtils.getString(map, "HouCon") != null && MapUtils.getString(map2, "HouCon") != null && MapUtils.getString(map, "HouCon").equals(MapUtils.getString(map2, "HouCon"))) {
                                map.putAll(map2);
                                System.out.println("map" + map);
                            }
                        }
                    }
                }
            }
            System.out.println("不收费维修师傅" + SysUserIdNoList);
            if (SysUserIdNoList.size() > 0) {//根据维修师傅编号去权限表查询维修师傅的名字
                params.put("SysUserId", SysUserIdNoList);
                JsonResult SysResult = zzuulFeign.getLoginName(params);//查询维修师傅的姓名
                List<Map<String, Object>> SysList = (List<Map<String, Object>>) SysResult.get("result");
                System.out.println("找到维修师傅名字的SysList" + SysList);
                if (SysResult.get("errorCode").equals("0")) {
                    for (Map<String, Object> map1 : IfCostNoList) {
                        for (Map<String, Object> map2 : SysList) {
                            if (MapUtils.getString(map1, "SysUserId") != null && MapUtils.getString(map2, "user_id") != null && MapUtils.getString(map1, "SysUserId").equals(MapUtils.getString(map2, "user_id"))) {
                                map1.putAll(map2);
                                System.out.println("map1" + map1);
                            }
                        }
                    }
                }
            }
            System.out.println("已支付的房源" + HouConYesList);
            if (HouConYesList.size() > 0) {//根据房源配置主表编号去市场部查询房源信息
                paramsYes.put("idList", HouConYesList);
                JsonResult zpcResult = zpcMktFeign.getCommunityListss(paramsYes);
                List<Map<String, Object>> zpcList = (List<Map<String, Object>>) zpcResult.get("result");
                System.out.println("zpcList" + zpcList);
                if (zpcResult.get("errorCode").equals("0")) {
                    for (Map<String, Object> map : IfCostYesList) {
                        for (Map<String, Object> map2 : zpcList) {
                            if (MapUtils.getString(map, "HouCon") != null && MapUtils.getString(map2, "HouCon") != null && MapUtils.getString(map, "HouCon").equals(MapUtils.getString(map2, "HouCon"))) {
                                map.putAll(map2);
                                System.out.println("map" + map);
                            }
                        }
                    }
                }
            }
            System.out.println("已支付的维修师傅" + SysUserIdNoList);
            if (SysUserIdYesList.size() > 0) {//根据维修师傅编号去权限表查询维修师傅的名字
                paramsYes.put("SysUserId", SysUserIdYesList);
                JsonResult SysResult = zzuulFeign.getLoginName(paramsYes);//查询维修师傅的姓名
                List<Map<String, Object>> SysList = (List<Map<String, Object>>) SysResult.get("result");
                System.out.println("找到维修师傅名字的SysList" + SysList);
                if (SysResult.get("errorCode").equals("0")) {
                    for (Map<String, Object> map1 : IfCostYesList) {
                        for (Map<String, Object> map2 : SysList) {
                            if (MapUtils.getString(map1, "SysUserId") != null && MapUtils.getString(map2, "user_id") != null && MapUtils.getString(map1, "SysUserId").equals(MapUtils.getString(map2, "user_id"))) {
                                map1.putAll(map2);
                                System.out.println("map1" + map1);
                            }
                        }
                    }
                }
            }

            System.out.println("已支付的账单" + OrdBiIdYesList);
            System.out.println("当前的已经维修完成，并且需要支付的维修工单"+IfCostYesList);
            System.out.println("进行筛选筛选支付没有完成");

            if (OrdBiIdYesList.size() > 0) {//根据维修师傅编号去权限表查询维修师傅的名字
                paramsYes.put("OrdBiIdList", OrdBiIdYesList);
                JsonResult OrdResult = gmioFeign.getTcmgioBillTwo(paramsYes);
                List<Map<String, Object>> OrdList = (List<Map<String, Object>>) OrdResult.get("result");
                System.out.println("查寻的结果" + OrdList);
                if(OrdList !=null&&OrdList.size()>0) {
                    if (OrdResult.get("errorCode").equals("0")) {
                        for (Map<String, Object> map1 : IfCostYesList) {
                            for (Map<String, Object> map2 : OrdList) {
                                if (MapUtils.getString(map1, "OrdBiId") != null && MapUtils.getString(map2, "Source") != null && MapUtils.getString(map1, "OrdBiId").equals(MapUtils.getString(map2, "Source"))) {
                                    map1.putAll(map2);
                                    System.out.println("map1" + map1);
                                }
                            }
                        }
                    }

                    //根据账单编号查询的不全部为空，根据null和值判断删除账单为没有支付完成的，保留支付完成的
                    for (int i=0;i<IfCostYesList.size();i++){
                        if (MapUtils.getInteger(IfCostYesList.get(i),"Status")!=2||null==MapUtils.getInteger(IfCostYesList.get(i),"Status")){
                            IfCostYesList.remove(i);
                        }
                    }

                }else{
                    //根据账单编号查询的全部为空，表示没有支付完成的没有。可以删除支付完成的
                    IfCostYesList.clear();
                }

            }


            List<Map<String, Object>> resultList = new ArrayList<>();
            resultList.addAll(IfCostNoList);//添加不需要支付
            resultList.addAll(IfCostYesList);//添加需要支付
            return result.put(resultList);
        } else {
            return result.put(new ArrayList<Map<String, Object>>());
        }

    }

    /**
     * <p>
     * 查询已完成
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult hasBeenCompleted(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        System.out.println("待评价接受的参数" + params);
        List<Map<String, Object>> evaluateList = tcepcArticleMapper.toEvaluate(params);
        System.out.println("查询维修完成(不管是否收费)" + evaluateList);
        Map<String, Object> paramsYes = new HashMap<>();
        //保存房源配置主表编号(未收费)
        List<String> HouConNoList = new ArrayList<>();
        //保存维修师傅的编号（未收费）
        List<String> SysUserIdNoList = new ArrayList<>();
        //保存房源配置主表编号(收费)
        List<String> HouConYesList = new ArrayList<>();
        //保存维修师傅的编号（收费）
        List<String> SysUserIdYesList = new ArrayList<>();
        //保存维修账单的编号（收费）
        List<String> OrdBiIdYesList = new ArrayList<>();
        //保存维修完成未收费和未评价的集合
        List<Map<String, Object>> IfCostNoList = new ArrayList<>();
        //保存维修完成，收费 和付款成功和未评价的集合
        List<Map<String, Object>> IfCostYesList = new ArrayList<>();
        if (evaluateList.size() > 0) {
            for (Map<String, Object> evaluateMap : evaluateList) {
                if (evaluateMap.get("IfCost") != null && MapUtils.getInteger(evaluateMap, "IfCost") == 0) {//检查不收费
                    if (evaluateMap.get("RepId") != null && tcepcArticleMapper.toEvaluateBeenCompleted(evaluateMap) == 1) {//检查已评价
                        HouConNoList.add(MapUtils.getString(evaluateMap, "HouCon"));
                        SysUserIdNoList.add(MapUtils.getString(evaluateMap, "SysUserId"));
                        IfCostNoList.add(evaluateMap);
                    }
                }
                if (evaluateMap.get("IfCost") != null && MapUtils.getInteger(evaluateMap, "IfCost") == 1) {//检查收费
                    if (evaluateMap.get("RepId") != null && tcepcArticleMapper.toEvaluateBeenCompleted(evaluateMap) == 1) {//检查未评价
                        HouConYesList.add(MapUtils.getString(evaluateMap, "HouCon"));
                        SysUserIdYesList.add(MapUtils.getString(evaluateMap, "SysUserId"));
                        OrdBiIdYesList.add(MapUtils.getString(evaluateMap, "OrdBiId"));
                        IfCostYesList.add(evaluateMap);
                    }
                }
                System.out.println("未支付的房源" + HouConNoList);
                if (HouConNoList.size() > 0) {//根据房源配置主表编号去市场部查询房源信息
                    params.put("idList", HouConNoList);
                    JsonResult zpcResult = zpcMktFeign.getCommunityListss(params);
                    List<Map<String, Object>> zpcList = (List<Map<String, Object>>) zpcResult.get("result");
                    System.out.println("zpcList" + zpcList);
                    if (zpcResult.get("errorCode").equals("0")) {
                        for (Map<String, Object> map : IfCostNoList) {
                            for (Map<String, Object> map2 : zpcList) {
                                if (MapUtils.getString(map, "HouCon") != null && MapUtils.getString(map2, "HouCon") != null && MapUtils.getString(map, "HouCon").equals(MapUtils.getString(map2, "HouCon"))) {
                                    map.putAll(map2);
                                    System.out.println("map" + map);
                                }
                            }
                        }
                    }
                }
                System.out.println("未支付的维修师傅" + SysUserIdNoList);
                if (SysUserIdNoList.size() > 0) {//根据维修师傅编号去权限表查询维修师傅的名字
                    params.put("SysUserId", SysUserIdNoList);
                    JsonResult SysResult = zzuulFeign.getLoginName(params);//查询维修师傅的姓名
                    List<Map<String, Object>> SysList = (List<Map<String, Object>>) SysResult.get("result");
                    System.out.println("找到维修师傅名字的SysList" + SysList);
                    if (SysResult.get("errorCode").equals("0")) {
                        for (Map<String, Object> map1 : IfCostNoList) {
                            for (Map<String, Object> map2 : SysList) {
                                if (MapUtils.getString(map1, "SysUserId") != null && MapUtils.getString(map2, "user_id") != null && MapUtils.getString(map1, "SysUserId").equals(MapUtils.getString(map2, "user_id"))) {
                                    map1.putAll(map2);
                                    System.out.println("map1" + map1);
                                }
                            }
                        }
                    }
                }
                System.out.println("已支付的房源" + HouConYesList);
                if (HouConYesList.size() > 0) {//根据房源配置主表编号去市场部查询房源信息
                    paramsYes.put("idList", HouConYesList);
                    JsonResult zpcResult = zpcMktFeign.getCommunityListss(paramsYes);
                    List<Map<String, Object>> zpcList = (List<Map<String, Object>>) zpcResult.get("result");
                    System.out.println("zpcList" + zpcList);
                    if (zpcResult.get("errorCode").equals("0")) {
                        for (Map<String, Object> map : IfCostYesList) {
                            for (Map<String, Object> map2 : zpcList) {
                                if (MapUtils.getString(map, "HouCon") != null && MapUtils.getString(map2, "HouCon") != null && MapUtils.getString(map, "HouCon").equals(MapUtils.getString(map2, "HouCon"))) {
                                    map.putAll(map2);
                                    System.out.println("map" + map);
                                }
                            }
                        }
                    }
                }
                System.out.println("已支付的维修师傅" + SysUserIdYesList);
                if (SysUserIdYesList.size() > 0) {//根据维修师傅编号去权限表查询维修师傅的名字
                    paramsYes.put("SysUserId", SysUserIdYesList);
                    JsonResult SysResult = zzuulFeign.getLoginName(paramsYes);//查询维修师傅的姓名
                    List<Map<String, Object>> SysList = (List<Map<String, Object>>) SysResult.get("result");
                    System.out.println("找到维修师傅名字的SysList" + SysList);
                    if (SysResult.get("errorCode").equals("0")) {
                        for (Map<String, Object> map1 : IfCostYesList) {
                            for (Map<String, Object> map2 : SysList) {
                                if (MapUtils.getString(map1, "SysUserId") != null && MapUtils.getString(map2, "user_id") != null && MapUtils.getString(map1, "SysUserId").equals(MapUtils.getString(map2, "user_id"))) {
                                    map1.putAll(map2);
                                    System.out.println("map1" + map1);
                                }
                            }
                        }
                    }
                }
                System.out.println("已支付的账单" + OrdBiIdYesList);
                if (OrdBiIdYesList.size() > 0) {//根据维修师傅编号去权限表查询维修师傅的名字
                    paramsYes.put("OrdBiIdList", OrdBiIdYesList);
                    JsonResult OrdResult = gmioFeign.getTcmgioBillTwo(paramsYes);
                    List<Map<String, Object>> OrdList = (List<Map<String, Object>>) OrdResult.get("result");
                    System.out.println("支付过的维修工单" + OrdList);
                    if (OrdResult.get("errorCode").equals("0")) {
                        for (Map<String, Object> map1 : IfCostYesList) {
                            for (Map<String, Object> map2 : OrdList) {
                                if (MapUtils.getString(map1, "OrdBiId") != null && MapUtils.getString(map2, "Source") != null && MapUtils.getString(map1, "OrdBiId").equals(MapUtils.getString(map2, "Source"))) {
                                    map1.putAll(map2);
                                    System.out.println("map1" + map1);
                                }
                            }
                        }
                    }
                }
            }
            List<Map<String, Object>> resultList = new ArrayList<>();
            resultList.addAll(IfCostNoList);
            resultList.addAll(IfCostYesList);
            return result.put(resultList);

        } else {
            return result.put(new ArrayList<Map<String, Object>>());
        }


    }

    /**
     * <p>
     * 维修师傅评价
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult getStarAvg(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        List<Map<String, Object>> paramsList = tcepcArticleMapper.getStarCount(params);
        Map<String, Object> para = new HashMap<>();
        int sum = 0;
        double avg;
        if (paramsList.size() > 0) {
            for (Map<String, Object> paraMap : paramsList) {
                sum = sum + MapUtils.getInteger(paraMap, "sstar").intValue();
            }
            avg = CompuUtils.div(sum, paramsList.size(), 1);
            para.put("avg", avg);
        }
        return result.put(para);
    }


    /**
     * <p>
     * 取消预约
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult deleteTcepcRepair(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        /**
         * 加锁操作
         */
        lock.lock();
        try {
            log.info("删除操作");
            System.out.println("params" + params);
            if (tcepcArticleMapper.deleteTcepcRepair(params) > 0) {
                result.putSuccess("取消预约成功!");
            } else {
                result.putFailed("取消预约失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事物回滚
            result.putFailed("服务器繁忙...");
        } finally {
            lock.unlock();
        }
        return result;
    }

    /**
     * <p>
     * 增加维修评价
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult insertRepairEva(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        /**
         * 加锁操作
         */
        lock.lock();
        try {
            log.info("增加操作");
            params.put("WxUser", params.get("TenId"));
            params.put("term", "1");//创建端  1 租客端 2市场部 3 工程部 4运营部 5财务部 6总经办 7发展部
            params.put("fnc",
                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
            ParamsCommon.commonInsertParms(params);
            System.out.println("添加的参数" + params);
            Integer a = tcepcArticleMapper.insertRepairEva(params);//增加维修评价
            if (a <= 0) {
                result.putFailed("评价失败!");
            }
            result.putSuccess("评价成功!");
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事物回滚
            result.putFailed("服务器繁忙...");
        } finally {
            lock.unlock();
        }
        return result;

    }

    /**
     * <p>
     * 查询保修物品清单分类
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult getTcepcArticleType() {
        JsonResult result = new JsonResult();
        return result.put(tcepcArticleMapper.getTcepcArticleType());
    }

    /**
     * <p>
     * 查询保修物品清单
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult getTcepcArtice(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        return result.put(tcepcArticleMapper.getTcepcArtice(params));
    }

    /**
     * <p>
     * 查询维修物品描述
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult getTcepcArticleTrouble(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        return result.put(tcepcArticleMapper.getTcepcArticleTrouble(params));
    }

    /**
     * <p>
     * 根据租客在线保修物品信息添加维修工单
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JsonResult insertTcepcRepair(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        /**
         * 加锁操作
         */
        lock.lock();
        try {
            log.info("增加操作");
            params.put("term", "1");//创建端  1 租客端 2市场部 3 工程部 4运营部 5财务部 6总经办 7发展部
            params.put("fnc",
                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
            ParamsCommon.commonInsertParms(params);
            params.put("RepairsId", params.get("TenId"));//报修人
            params.put("by", params.get("TenId"));//操作人
            System.out.println("params" + params);
            //维修图片
            List<Map<String, Object>> TroubleFileList = (List<Map<String, Object>>) params.get("TroubleFile");
            String TroubleFile = FileSubufferUtils.ListFlieStringUtils(TroubleFileList);
            params.put("TroubleFile", TroubleFile);//图片
            String UUID;
            Map<String, Object> uuid = utilsMapper.getUUID(new HashMap<String, Object>() {{
                put("uuid", "RepId");
                put("database", Constants.DATA_SOURCE_TCEPC);
                put("surface", "tcepc_repair");
            }});
            if (uuid != null) {
                int number = Integer.valueOf(uuid.get("uuid").toString());
                UUID = ComUtils.getLocalTrmSeqNum("wxdg", number);
            } else {
                UUID = ComUtils.getLocalTrmSeqNum("wxdg", 0);
            }
            params.put("RepId", UUID);
            Integer a = tcepcArticleMapper.insertTcepcRepair(params);
            if (a <= 0) {
                result.putFailed("提交申请失败!");
            }
            result.putSuccess("提交申请成功!");

            //通知
            //新维修单
            CustomMap data = CustomMap.create("MeType", 8)
                    .put("Title", "新维修工单")
                    .put("Content", HtmlUtil.stringToHTML("租客发起新的维修工单！；", "", Color.blue))
                    .put("term", 3);
            zzuulFeign.AddMessage(data);

        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事物回滚
            result.putFailed("服务器繁忙...");
        } finally {
            lock.unlock();
        }
        return result;
    }


}
